module.exports = function (req, res, config) {
    try {
        ({ 'post': post, }[req.method.toLowerCase()])(req, res, config)
    } catch (error) {
        console.log(error);
        res.error(500)
    }
}

function post(req, res) {
    try {
        if (!req.body) throw ('uid不能为空！');
        let uid = req.body.uid;
        let data = req.body.data || false;
        if (!uid) throw ('uid不能为空！');
        if (!data) throw ('data不能为空！');
        let userinfo = true;
        Object.keys(req.socketUser).forEach(e => {
            if (req.socketUser[e].userinfo && req.socketUser[e].userinfo.uid == uid) {
                req.socketUser[e].socketEvent.emit('message', data);
                res.success('ok');
                userinfo = false;
                return;
            }
        });
        if (userinfo) throw ('发送失败，可能是用户不在线');

    } catch (error) {
        res.info('推送错误：', error)
    }
}
